package com.gree.flowable.app.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gree.flowable.app.pojo.form.FlwFormNodeset;
import com.gree.flowable.app.pojo.form.FormInfo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author ：180849
 * @date ：Created in 2021/4/14 8:46
 * @description：表单与模型节点关系
 * @modified By：
 * @version: 1.0
 */
@Repository
public interface FlwFormNodesetMapper extends BaseMapper<FlwFormNodeset> {

    /**
     * 添加表单与流程节点的关系
     * @param formType  流程节点与表单
     * @return              插入的条数
     */
//    Integer addFormNode(@Param("list")List<FlwFormNodeset> flwFormNodesetList);

    @Select("select fi.* from flw_form_nodeset ffn ,form_info fi where ffn.form_id  = fi.form_id and fi.form_type = #{formType} and ffn.process_key =#{processKey}")
    @ResultType(FormInfo.class)
    List<FormInfo> selectInfoByKeyAndType(String processKey, Integer formType);

    /**
     * 更新流程节点信息
     * @param processKey    流程关键字
     * @param formId        表单ID
     * @return
     */
//    Integer updateFormNode(String processKey,String formId);

    /**
     * 获取表单id
     * @param processKey
     * @return
     */
    @Select("select distinct form_id from flw_form_nodeset ffn where ffn.process_key =#{processKey}")
    @ResultType(String.class)
    String getFormId(@Param("processKey") String processKey);

    /**
     * 获取表单id，通过表状态进行过滤
     * @param processKey    模型的Key
     * @param formType      表单类型
     * @return
     */
    @Select("select distinct ffn.form_id from flw_form_nodeset ffn \n" +
            "left join form_info fi on fi.form_id = ffn.form_id \n" +
            "where fi.form_type = #{formType} and ffn.process_key =#{processKey}")
    @ResultType(String.class)
    String getFormIdByTypeAndProcessKey(@Param("processKey") String processKey, @Param("formType") Integer formType);

}
